package toolkit.dart.porting.actions;

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;

import org.eclipse.jface.text.BadLocationException;

import toolkit.dart.porting.processor.PortingProcessor;

public class PortJavaCodeActionDelegate extends TextSelectionActionDelegate {

	@Override
	protected void runForText(String text) {
		try {
			String result = PortingProcessor.process(text);
			if (result == null) {
				System.err.println("Bug while porting!");
			} else {
				StringSelection selection = new StringSelection(result);
				Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
				clipboard.setContents(selection, selection);
			}
		} catch (BadLocationException e) {
			System.err.println("Detected a bug!");
			e.printStackTrace();
		}
	}

}
